package org.example.student_dormitory.dao.impl;

import org.example.student_dormitory.dao.AdminDao;
import org.example.student_dormitory.entity.Admin;
import org.example.student_dormitory.utils.DBUtils;

import java.util.Map;

public class AdminDaoImpl implements AdminDao {
    //根据用户名和密码以及状态值,查询系统管理员数据
    @Override
    public Admin selectByAdmin(String username, String password, int dr) {
//        System.out.println("进入Dao");
        String sql = "select * from admin where username =? and password =? and dr =?";
        Map<String, Object> adminMaps = DBUtils.qureyOne(sql, username, password, dr);

        if (adminMaps == null) {
            // 说明没有数据
//            System.out.println("说明没有数据");
            return null;
        }else {
            Admin admin = new Admin();
            //实体对象中的id为long类型,所以需要转换
            admin.setId(Long.parseLong(adminMaps.get("id").toString()));
            admin.setUsername(username);
            admin.setPassword(password);
            admin.setDr(dr);
            admin.setName(adminMaps.get("name").toString());
            admin.setGender(adminMaps.get("gender").toString());
            admin.setPhone(adminMaps.get("phone").toString());
            return admin;
        }
    }
}
